/* 
 * Bitmain Tech, Home of Professional Bitmain Tech
 * Copyright 2014 Bitmain Tech Inc. and/or its affiliates and other contributors
 * as indicated by the @author tags. All rights reserved.
 * See the copyright.txt in the distribution for a
 * full listing of individual contributors.
 */
package com.bitmain.mmst.common.consts;

import java.util.Locale;

import javax.servlet.http.HttpServletRequest;

import org.springframework.web.servlet.i18n.SessionLocaleResolver;
import org.springframework.web.util.WebUtils;

import com.bitmain.mmst.common.util.SpringContextHolder;

/**
 * 错误码常量定义
 *
 * @author Kweny - enkun.jiang@bitmain.com
 * @since 2015年12月30日
 *
 */
public interface ResultCode {
	public static interface INFO {
		public static final int INFO = 100000000;
		
		public static final int SUCCESS = 101000000;
		public static final int SUCCESS_ADD = 101001000;
		public static final int SUCCESS_REMOVE = 101002000;
		public static final int SUCCESS_MODIFY = 101003000;
		public static final int SUCCESS_QUERY = 101004000;
		
		public static final int EXECUTE = 102000000;
		public static final int EXECUTE_UPDATE = 102001000;
		public static final int EXECUTE_UPDATE_NOW = 102001001;
		public static final int EXECUTE_UPDATE_QUEUE = 102001002;
		public static final int EXECUTE_SETUP = 102002000;
		public static final int EXECUTE_SETUP_NOW = 102002001;
		public static final int EXECUTE_SETUP_QUEUE = 102002002;
	}
	
	public static interface WARN {
		public static final int WARN = 200000000;
		
		public static final int DB = 201000000;
		public static final int DB_INSERT = 201001000;
		public static final int DB_DELETE = 201002000;
		public static final int DB_UPDATE = 201003000;
		public static final int DB_SELECT = 201004000;
		public static final int DB_SELECT_NonData = 201004001;
	}
	
	public static interface ERROR {
		/** 未知错误 */
		public static final int ERROR = 300000000;
		
		/** 数据库错误 */
		public static final int DB = 301000000;
		/** 数据库错误：插入错误 */
		public static final int DB_INSERT = 301001000;
		/** 数据库错误：删除错误 */
		public static final int DB_DELETE = 301002000;
		/** 数据库错误：更新错误 */
		public static final int DB_UPDATE = 301003000;
		/** 数据库错误：查询错误 */
		public static final int DB_SELECT = 301004000;
		
		/** 操作错误 */
		public static final int OPE = 302000000;
		
		/** 执行错误 */
		public static final int EXE = 303000000;
		/** 固件升级错误 */
		public static final int EXE_UPDATE = 303001000;
		/** 固件升级错误 ：提交矿机固件升级任务时，所选固件不存在 */
		public static final int EXE_UPDATE_NONFIRMWARE = 303001001;
		/** 固件升级错误 ：提交矿机固件升级任务时，脚本文件不存在且创建失败 */
		public static final int EXE_UPDATE_NONCOMMAND = 303001002;
		/** 固件升级错误：按IP升级固件时，所选文件不包含任何IP */
		public static final int EXE_UPDATE_NONIP = 303001003;
		/** 固件升级错误：按IP升级固件时，IP文件读取错误 */
		public static final int EXE_UPDATE_IPFILE = 303001004;
		/** 固件配置错误：按机架配置时，机架为空 */
		public static final int EXE_SETUP_NONSHELFS = 303002001;
		/** 固件配置错误：按IP配置时，所选文件不包含任何IP */
		public static final int EXE_SETUP_NONIP = 303002002;
		/** 固件配置错误：按IP配置时，IP文件读取错误 */
		public static final int EXE_SETUP_IPFILE = 303002003;
		/** 固件配置错误：无效的矿池信息 */
		public static final int EXE_SETUP_INVALIDPOOLS = 303002004;
		
		/** 验证错误 */
		public static final int VER = 304000000;
		/** 验证错误：空数据（null） */
		public static final int VER_NULL = 304001000;
		/** 验证错误：空数据（empty） */
		public static final int VER_EMPTY = 304002000;
		public static final int VER_EMPTY_COLLECTION = 304002001;
		/** 验证错误：空数据（blank） */
		public static final int VER_BLANK = 304003000;
		/** 验证错误：数据无效 */
		public static final int VER_INVALID = 304004000;
		/** 验证错误：数据格式错误 */
		public static final int VER_FORMAT = 304005000;
		/** 验证错误：数据重复 */
		public static final int VER_DUPLICATE = 304006000;
		public static final int VER_DUPLICATE_NAME = 304006001;
		public static final int VER_DUPLICATE_IPBLOCK = 304006002;
		/** 验证错误：最大长度 */
		public static final int VER_MAX_LENGTH = 304007000;
		/** 验证错误：最小长度 */
		public static final int VER_MIN_LENGTH = 304008000;
		/** 验证错误：长度 */
		public static final int VER_LENGTH = 304009000;
		/** 验证错误：不存在 */
		public static final int VER_NONEXISTENT = 304010000;
		/** 验证错误：数据被占用 */
		public static final int VER_OCCUPIED = 304011000;
		
		public static final int FILE = 305000000;
		public static final int FILE_UPLOAD = 305001000;
		public static final int FILE_UPLOAD_NULL = 305001001;
		public static final int FILE_UPLOAD_TYPE = 305001002;
		public static final int FILE_UPLOAD_SIZE = 305001003;
		public static final int FILE_UPLOAD_IO = 305001004;
		public static final int FILE_EXPORT = 305002000;
		public static final int FILE_EXPORT_NONDATA = 305002001;
		
		/** 监控错误 */
		public static final int MM = 306000000;
		/** 监控错误：统计 */
		public static final int MM_STATISTIC = 306001000;
		/** 监控错误：统计 - 矿场运营配置为空 */
		public static final int MM_STATISTIC_NonSituationOption = 306001001;
		/** 指定日期的运营配置被占用（正在进行统计） */
		public static final int MM_STATISTIC_SituationOccupied = 306001002;
	}
	
	public static class Message {
		public static String get(HttpServletRequest request, int error, Object... args) {
			Locale locale = (Locale) WebUtils.getSessionAttribute(request, SessionLocaleResolver.LOCALE_SESSION_ATTRIBUTE_NAME);
			return SpringContextHolder.getApplicationContext().getMessage(String.valueOf(error), args, locale);
		}
	}
}
